﻿using FreeSql.DataAnnotations;

using RsCode;
using Rswl.Common.Core.User.Aggregate.ValueObject;

namespace Rswl.Common.Core.User.Aggregate.Entities
{
    [Table(Name="rswl_user_password")]
    public class PasswordInfo
    {
        public PasswordInfo()
        {
                
        }
        /// <summary>
        /// 创建一个密码信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="password"></param>
        /// <param name="pwdType"></param>
        public PasswordInfo(string userId,string password,PasswordType pwdType= PasswordType.PwdLogin)
        {
            UserId=userId;
            Salt=Guid.NewGuid().ToString("N");
			Password = SecureHelper.AESEncrypt(password, Salt);
            PasswordType = pwdType;
        }

        public void ChangePassword(string password)
        {
            Salt = Guid.NewGuid().ToString("N");
            Password = SecureHelper.AESEncrypt(password, Salt);
        }

        public bool VerifyPassword(string password)
        {
           var pwd = SecureHelper.AESEncrypt(password, Salt);    
            return pwd == Password;
        }
        [Column(IsIdentity =true)]
        public long Id { get; set; }
       
        public string UserId { get; set; }
   
        public string Password { get; set; }
      
        public string Salt { get; set; }

        public PasswordType PasswordType { get; set; }
    }
}
